﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMS_Master.DTO.Personnel;
using TMS_Master.Personnel_module;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace TMS_Master
{
    public class StaffService : CrudAppService //Defines CRUD methods
        <Staff,
        StaffDTO,
        Guid,
        PagedAndSortedResultRequestDto,
        StaffDTOText>,
        IStaffService
    {
        public readonly IRepository<Staff, Guid> tMSApp;
        public StaffService(IRepository<Staff, Guid> _tMSApp) : base(_tMSApp)
        {
            tMSApp = _tMSApp;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="Staff"></param>
        /// <returns></returns>
        public async Task<int> AddStaff(StaffDTO Staff)
        {
            Staff Add = ObjectMapper.Map<StaffDTO, Staff>(Staff);
            await tMSApp.InsertAsync(Add);
            return 1;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task DelStaff(Guid Id)
        {
            await tMSApp.DeleteAsync(Id);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<StaffDTO> FanStaff(Guid Id)
        {
            Staff b = await tMSApp.GetAsync(Id);
            StaffDTO fan = ObjectMapper.Map<Staff, StaffDTO>(b);
            return fan;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public async Task<List<StaffDTO>> GetStaff()
        {
            List<Staff> p = await tMSApp.ToListAsync();
            List<Staff> becomes = p;
            List<StaffDTO> becomeDTOs = ObjectMapper.Map<List<Staff>, List<StaffDTO>>(becomes);
            return becomeDTOs;

        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="become"></param>
        /// <returns></returns>
        public async Task<int> UptStaff(StaffDTO become)
        {
            Staff e = await tMSApp.GetAsync(become.Id);
            e.StaffName = become.StaffName;
            return 1;
        }
    }
}
